<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            width: 600px;
            margin: 100px auto;
        }
        .message{
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url("img/up.jpg") no-repeat left center;
            padding-left: 20px;
        }
        .wrong{
            color: red;
            background-image: url("img/down.jpg");
        }
        .right{
            color: green;
            background-image: url("img/up.jpg");
        }
    </style>
</head>
<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6-16位密码</p>
    </div>
    <script>
        //首先判断事件是表单失去焦点 onblur
        //如果输入正确则提示正确的信息颜色为
        var ipt = document.querySelector('.ipt');
        var message = document.querySelector('.message');
        ipt.onblur = function () {
            //根据表单里值得长度ipt.value.length
            if (this.value.length < 6 || this.value.length > 16){
                message.className = 'message wrong';
                message.innerHTML = '位数要求6-16位';
            }else {
                message.className = 'message right';
                message.innerHTML = '输入正确';
            }
        }

    </script>
</body>
</html>